const API_ROOT = 'https://www.6bei.net/api/';//API
// const API_ROOT = 'http://192.168.1.8/api/';//API
const IMG_ROOT = 'https://www.6bei.net';//API
const OSS = 'https://www.6bei.net/';//API

const LOGIN_ROUTE = '/pages/public/login';//登录页
const UPDATE_API = 'upgrade';//升级URI
const ENCRYPT = false;//加密
const EFFECT_ON = false;//是否开启页面效果
const MAIN_COLOR = 'rgba(128,128,0,1)';

//系统配置
const app_settig = {
	'root':API_ROOT,
	'img':IMG_ROOT,
	'oss':OSS,
	'encrypt':ENCRYPT, 
	'login_route':LOGIN_ROUTE,
	'update_api':UPDATE_API,
	'effect_on':EFFECT_ON,
	'main_color':MAIN_COLOR
};

//通用配置
const Config = (param) =>{
	let name = getParam(param,'name','');
	let val = getParam(param,'value','');	
	if(!name.has)return '_NULL_';
	if(!val.has){
		let key = name.value;
		let data = uni.getStorageSync(key) || '_NULL_';		
		return data;		
	}else{
		let key = name.value;
		let value = val.value;		
		uni.setStorageSync(key,value);
	}
}
//取得attr
const getAttr = (name,e) =>{
	return e.currentTarget.dataset[name];	
}

//加载中
const loading = (msg) =>{
	if(!msg)msg = '加载中'
	uni.showLoading({		
		title:msg
	})
}

const meTitle = (title)=>{
	uni.setNavigationBarTitle({
		title:title
	})
}

const getParam = (param,name,def)=>{
	if(!param.hasOwnProperty(name))return {has:false,value:def};
	return  {has:true,value:param[name]};
}

module.exports = {    
	Config:Config,
	Setting:app_settig,
	getAttr:getAttr,
	loading:loading,
	getParam:getParam,
	meTitle:meTitle,	
}